<?php
	include_once("./include/ActivitiesClass.php");
	$ActivClass = new ActivitiesClass();
	$userID = $_SESSION['user']['id'];
   
   
       if (!empty($_GET['action']))
        {
            if (!empty($_GET['go']))
            {
                $type = $_GET['type'];
                $ctr = $_GET['ctr'];
				$cost = $_GET['cost'];
				$weekCost = $_GET['weekCost'];
				$startTime = $_GET['startTime'];
				$endTime = $_GET['endTime'];
				$descr = $_GET['descr'];
				$duration = $_GET['duration'];
				$amount = $_GET['amount'];

                switch ($_GET['action'])
                {
                    case 'new' :{
                                    $activeSession = $_SESSION['user']['session'];
                                    $activeSession = $_SESSION['user']['session'];
                                    $result = $ActivClass->addNewActive($userID,$activeSession,$type,$ctr,$cost,$weekCost,
																		$startTime,$endTime,$descr,$duration,$amount);
                                    break;
                                }

                    case 'upd' :{
                                    $id = $_GET['id'];
                                    $result = $ActivClass->updateActive($id,$name,$descr, $picture);
                                    break;
                                }

                    case 'del' :{
                                    $id = $_GET['id'];
                                    $result = $ActivClass->deleteactive($id);
                                    break;
                                }
                }
                if ($result==true)
                {
                    echo "Done! ! !";
                    
                    echo "<script>setTimeout(\"document.location.href='index.php?tabID=sellerMain&subID=Activities'\",3000);</script>";
                    return;
                }
                else
                    echo "error - $result";
            }
           else
           {
           require_once('addActiveForm.php');
           return;
           }
        }
		
   echo "<h2 align=center>Activities</h2>";
  
   echo "<input type='button' class='newButton' onClick=\"document.location.href='index.php?tabID=sellerMain&subID=Activities&action=new'\" value='Add new Activity'>";
   
   echo "
               <table class='auctionListTable'>
                    <tr class='auctionListCat'>
                            <td>Activity Id</td>
							<td>Type</td>
                            <td>Description</td>
                            <td>Amount</td>
                            <td>Price</td>
                            <td>Start Time</td>
                            <td>End Time</td>
							<td>Edit</td>
							<td>Stop Campaign</td>
							</tr>";
							
		$result = $ActivClass->getActiveList($userID);
        $num = mysql_num_rows($result);
        $i=0;
        if ($num==0)
            "<font size=\"4\" color=\"red\">No Activities found</font>";
        else 
        {
            while($row = mysql_fetch_array($result))
            {
                  echo "<tr class='activitiesLines'>
                            <td onclick=\"document.location.href='index.php?tabID=adminMain&subID=userStats&userID=".$row['id']."'\">".$row['id']."</td>
							<td onclick=\"document.location.href='index.php?tabID=adminMain&subID=userStats&userID=".$row['type']."'\">".$row['type']."</td>
                            <td onclick=\"document.location.href='index.php?tabID=adminMain&subID=userStats&userID=".$row['id']."'\">".$row['descr']."</td>
                            <td onclick=\"document.location.href='index.php?tabID=adminMain&subID=userStats&userID=".$row['id']."'\">".$row['amount']."</td>
							<td onclick=\"document.location.href='index.php?tabID=adminMain&subID=userStats&userID=".$row['id']."'\">".$row['cost']."</td>
							<td onclick=\"document.location.href='index.php?tabID=adminMain&subID=userStats&userID=".$row['id']."'\">".$row['startTime']."</td>
							<td onclick=\"document.location.href='index.php?tabID=adminMain&subID=userStats&userID=".$row['id']."'\">".$row['endTime']."</td>";
                  echo     "<td><a href=\"./index.php?tabID=adminMain&subID=createActivities&action=upd&id=". $row['id'] ."\"><img src='images/update.png' alt='upd' class='updateImg'></a></td> 
							<td><a href=\"./index.php?tabID=adminMain&subID=createActivities&action=del&id=". $row['id'] ."\"><img src='images/delete.png' alt='del' class='deleteImg'></a></td>
                            
                        </tr>";
            }
        }      
        echo   "</table><br />";
?>
    
